<template>
  <div class="app-container">
  <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<!--    <el-form-item label="用户id" prop="userId">-->
<!--      <el-input-->
<!--        v-model="queryParams.userId"-->
<!--        placeholder="请输入用户id"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="一卡通号" prop="insCartId">-->
<!--      <el-input-->
<!--        v-model="queryParams.insCartId"-->
<!--        placeholder="请输入一卡通号"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
    <el-form-item label="姓名" prop="insName">
      <el-input
        v-model="queryParams.insName"
        placeholder="请输入姓名"
        clearable
        size="small"
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
<!--    <el-form-item label="像片" prop="insPicture">-->
<!--      <el-input-->
<!--        v-model="queryParams.insPicture"-->
<!--        placeholder="请输入像片"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
    <el-form-item label="性别" prop="insGender">
      <el-select v-model="queryParams.insGender" placeholder="请选择性别" clearable size="small">
        <el-option
          v-for="dict in insGenderOptions"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
        />
      </el-select>
    </el-form-item>
<!--    <el-form-item label="职称" prop="insProfessor">-->
<!--      <el-input-->
<!--        v-model="queryParams.insProfessor"-->
<!--        placeholder="请输入职称"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="职务" prop="insCommander">-->
<!--      <el-input-->
<!--        v-model="queryParams.insCommander"-->
<!--        placeholder="请输入职务"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="研究方向" prop="insDirection">-->
<!--      <el-input-->
<!--        v-model="queryParams.insDirection"-->
<!--        placeholder="请输入研究方向"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="出生年月" prop="insBirth">-->
<!--      <el-date-picker clearable size="small"-->
<!--                      v-model="queryParams.insBirth"-->
<!--                      type="date"-->
<!--                      value-format="yyyy-MM-dd"-->
<!--                      placeholder="选择出生年月">-->
<!--      </el-date-picker>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="籍贯" prop="insNativePlace">-->
<!--      <el-input-->
<!--        v-model="queryParams.insNativePlace"-->
<!--        placeholder="请输入籍贯"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="政治面貌" prop="insPoliticalOutlook">-->
<!--      <el-input-->
<!--        v-model="queryParams.insPoliticalOutlook"-->
<!--        placeholder="请输入政治面貌"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="学历" prop="insEducation">-->
<!--      <el-input-->
<!--        v-model="queryParams.insEducation"-->
<!--        placeholder="请输入学历"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="学位" prop="insAcademicDegree">-->
<!--      <el-input-->
<!--        v-model="queryParams.insAcademicDegree"-->
<!--        placeholder="请输入学位"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="手机号" prop="insMobile">-->
<!--      <el-input-->
<!--        v-model="queryParams.insMobile"-->
<!--        placeholder="请输入手机号"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="办公电话" prop="insPhone">-->
<!--      <el-input-->
<!--        v-model="queryParams.insPhone"-->
<!--        placeholder="请输入办公电话"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="电子邮箱" prop="insEmail">-->
<!--      <el-input-->
<!--        v-model="queryParams.insEmail"-->
<!--        placeholder="请输入电子邮箱"-->
<!--        clearable-->
<!--        size="small"-->
<!--        @keyup.enter.native="handleQuery"-->
<!--      />-->
<!--    </el-form-item>-->
    <el-form-item label="审核状态" prop="examineStatus">
      <el-select v-model="queryParams.examineStatus" placeholder="请选择审核状态" clearable size="small">
        <el-option :label="status.label" :value="status.value" v-for="status in examineStatusOptions" />
      </el-select>
    </el-form-item>
    <el-form-item style="margin-left: 50px;">
      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>

  <el-row :gutter="10" class="mb8">
    <el-col :span="1.5">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        v-hasPermi="['mentor:instructor:add']"
      >新增</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="success"
        plain
        icon="el-icon-edit"
        size="mini"
        :disabled="single"
        @click="handleUpdate"
        v-hasPermi="['mentor:instructor:edit']"
      >修改</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="danger"
        plain
        icon="el-icon-delete"
        size="mini"
        :disabled="multiple"
        @click="handleDelete"
        v-hasPermi="['mentor:instructor:remove']"
      >删除</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="warning"
        plain
        icon="el-icon-download"
        size="mini"
        @click="handleExport"
        v-hasPermi="['mentor:instructor:export']"
      >导出</el-button>
    </el-col>
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  </el-row>

  <el-table v-loading="loading" :data="instructorList" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" align="center" />
<!--    <el-table-column label="一卡通号" align="center" prop="insCartId" />-->
    <el-table-column label="姓名" align="center" prop="insName" />
    <el-table-column label="像片" align="center" prop="insPicture" >
      <template slot-scope="scope">
        <img style="border-radius: 50%;width: 40px;height: 40px;" :src="scope.row.insPicture" alt="">
      </template>
    </el-table-column>
    <el-table-column label="性别" align="center" prop="insGender" >
      <template slot-scope="scope">
        <el-tag type="danger" v-if="scope.row.insGender==0">女</el-tag>
        <el-tag v-if="scope.row.insGender==1">男</el-tag>
      </template>
    </el-table-column>
<!--    <el-table-column label="职称" align="center" prop="insProfessor"/>-->
<!--    <el-table-column label="职务" align="center" prop="insCommander" />-->
<!--    <el-table-column label="研究方向" align="center" prop="insDirection" />-->
<!--    <el-table-column label="出生年月" align="center" prop="insBirth" width="120">-->
<!--      <template slot-scope="scope">-->
<!--        <span>{{ parseTime(scope.row.insBirth, '{y}-{m}-{d}') }}</span>-->
<!--      </template>-->
<!--    </el-table-column>-->
<!--    <el-table-column label="籍贯" align="center" prop="insNativePlace" />-->
<!--    <el-table-column label="政治面貌" align="center" prop="insPoliticalOutlook" />-->
<!--    <el-table-column label="学历" align="center" prop="insEducation" />-->
<!--    <el-table-column label="学位" align="center" prop="insAcademicDegree" />-->
    <el-table-column label="手机号" align="center" prop="insMobile" />
<!--    <el-table-column label="办公电话" align="center" prop="insPhone" />-->
<!--    <el-table-column label="电子邮箱" align="center" prop="insEmail" />-->
    <el-table-column label="审核状态" align="center" prop="examineStatus">
      <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.examineStatus==0">未审核</el-tag>
          <el-tag v-if="scope.row.examineStatus==1">审核中</el-tag>
          <el-tag type="danger" v-if="scope.row.examineStatus==2">审核未通过</el-tag>
          <el-tag type="success" v-if="scope.row.examineStatus==3">审核通过</el-tag>
      </template>
    </el-table-column>
    <el-table-column label="创建时间" align="center" prop="createDate" width="120">
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
    <el-table-column label="修改时间" align="center" prop="updateDate" width="120">
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-more"
            @click="toDetail(scope.row.id)"
          > 详细信息</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mentor:instructor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mentor:instructor:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  <!-- 添加或修改导师基本信息对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="用户id" prop="userId">
        <el-input v-model="form.userId" placeholder="请输入用户id" />
      </el-form-item>
      <el-form-item label="一卡通号" prop="insCartId">
        <el-input v-model="form.insCartId" placeholder="请输入一卡通号" />
      </el-form-item>
      <el-form-item label="姓名" prop="insName">
        <el-input v-model="form.insName" placeholder="请输入姓名" />
      </el-form-item>
      <el-form-item label="像片" prop="insPicture">
        <el-input v-model="form.insPicture" placeholder="请输入像片" />
      </el-form-item>
      <el-form-item label="性别" prop="insGender">
        <el-select v-model="form.insGender" placeholder="请选择性别">
          <el-option
            v-for="dict in insGenderOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="parseInt(dict.dictValue)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="职称" prop="insProfessor">
        <el-input v-model="form.insProfessor" placeholder="请输入职称" />
      </el-form-item>
      <el-form-item label="职务" prop="insCommander">
        <el-input v-model="form.insCommander" placeholder="请输入职务" />
      </el-form-item>
      <el-form-item label="研究方向" prop="insDirection">
        <el-input v-model="form.insDirection" placeholder="请输入研究方向" />
      </el-form-item>
      <el-form-item label="出生年月" prop="insBirth">
        <el-date-picker clearable size="small"
                        v-model="form.insBirth"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择出生年月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="籍贯" prop="insNativePlace">
        <el-input v-model="form.insNativePlace" placeholder="请输入籍贯" />
      </el-form-item>
      <el-form-item label="政治面貌" prop="insPoliticalOutlook">
        <el-input v-model="form.insPoliticalOutlook" placeholder="请输入政治面貌" />
      </el-form-item>
      <el-form-item label="学历" prop="insEducation">
        <el-input v-model="form.insEducation" placeholder="请输入学历" />
      </el-form-item>
      <el-form-item label="学位" prop="insAcademicDegree">
        <el-input v-model="form.insAcademicDegree" placeholder="请输入学位" />
      </el-form-item>
      <el-form-item label="手机号" prop="insMobile">
        <el-input v-model="form.insMobile" placeholder="请输入手机号" />
      </el-form-item>
      <el-form-item label="办公电话" prop="insPhone">
        <el-input v-model="form.insPhone" placeholder="请输入办公电话" />
      </el-form-item>
      <el-form-item label="电子邮箱" prop="insEmail">
        <el-input v-model="form.insEmail" placeholder="请输入电子邮箱" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
  </div>
</template>

<script>
import { listInstructor, getInstructor, delInstructor, addInstructor, updateInstructor, exportInstructor } from "@/api/mentor/instructor";
import { getToken } from "@/utils/auth";
export default {
  name: "Instructor",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 导师基本信息表格数据
      instructorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        insCartId: undefined,
        insName: undefined,
        insPicture: undefined,
        insGender: undefined,
        insProfessor: undefined,
        insCommander: undefined,
        insDirection: undefined,
        insBirth: undefined,
        insNativePlace: undefined,
        insPoliticalOutlook: undefined,
        insEducation: undefined,
        insAcademicDegree: undefined,
        insMobile: undefined,
        insPhone: undefined,
        insEmail: undefined,
        examineStatus: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ],
        insCartId: [
          { required: true, message: "一卡通号不能为空", trigger: "blur" }
        ],
        isDeleted: [
          { required: true, message: "删除标记不能为空", trigger: "blur" }
        ]
      },
      insGenderOptions: [{
        "label": "女",
        "value": 0
      }, {
        "label": "男",
        "value": 1
      }],
      examineStatusOptions:[
        {
          value:0,
          label:'未审核'
        },
        {
          value:1,
          label:'审核中'
        },
        {
          value:2,
          label:'审核未通过'
        },
        {
          value:3,
          label:'审核已通过'
        }
      ],
      // 上传参数
      upload: {
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/upload",
        // 上传的文件列表
        fileList: []
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询导师列表 */
    getList() {
      this.loading = true;
      listInstructor(this.queryParams).then(response => {
        this.instructorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        insCartId: undefined,
        insName: undefined,
        insGender: undefined,
        insProfessor: undefined,
        insCommander: undefined,
        insPicture: undefined,
        insMobile: undefined,
        insMobileShow: undefined,
        insPhone: undefined,
        insPhoneShow: undefined,
        insEmail: undefined,
        insEmailShow: undefined
      };
      this.resetForm("form");
    },
    insPictureBeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 10
      if (!isRightSize) {
        this.$message.error('文件大小超过 10MB')
      }
      return isRightSize
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      // console.log(response,file,fileList)
      this.form.insPicture = response.msg
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加导师";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInstructor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改导师";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInstructor(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInstructor(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除导师编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInstructor(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有导师数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInstructor(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },
    toDetail(id){
      this.$router.push(`/instructor/detail/${id}`)
    }
  }
};
</script>
